// import WechatCodeHandle from './codeEr/WechatCodeHandleeHandle';
export const getBodyZoom = function () {
  const w = document.documentElement.getBoundingClientRect().width
  const h = document.documentElement.getBoundingClientRect().height
  const maxWidth = 1920
  const maxHeight = 1080
  let zoom = 1
  if (h > w - 400) {
    zoom = w / maxWidth
  } else {
    zoom = h / maxHeight
    if (w / h > 3 && w / maxWidth > 2) {
      zoom += 0.1
    }
  }
  return zoom
}
const zoom = {
  beforeMount(el: { style: { zoom: number } }) {
    el.style.zoom = getBodyZoom()
    window.addEventListener(
      "resize",
      function () {
        el.style.zoom = getBodyZoom()
      },
      false
    )
  }
}

// wheel滚轮事件
const wheel = {
  x: 1,
  y: 1,
  minScale: 0.5,
  mounted(el: HTMLElement) {
    el.addEventListener(
      "wheel",
      function (e) {
        if (e.deltaY > 0) {
          wheel.x += 0.1
          wheel.y += 0.1
        } else {
          if (wheel.x > 0.6) {
            wheel.x -= 0.1
            wheel.y -= 0.1
          }
        }
        el.style.transform = `scale(${(wheel.x, wheel.y)})`
      },
      false
    )
  }
}

const preventReClick = {
  // 指令的定义
  mounted(el: any, binding: any) {
    el.addEventListener("click", () => {
      if (!el.disabled) {
        el.disabled = true
        el.style.cursor = "not-allowed"
        setTimeout(() => {
          el.disabled = false
          el.style.cursor = "pointer"
        }, binding.value || 1000)
      }
    })
  }
}

export default {
  zoom,
  wheel,
  preventReClick
}
